cc.Class({
    extends: cc.Component,
	
	getLocalTime:function(){
		var testDate = new Date();
		return testDate.getFullYear()+"-"+(testDate.getMonth()+1)+"-"+testDate.getDate()+" "+testDate.getHours()+":"+testDate.getMinutes()+":"+testDate.getSeconds();
	},
	
	getSavedTime:function(index){
		return cc.sys.localStorage.getItem("mt-saved-time-"+index)
	},

    saveGame:function(config,game,index){
		
		console.log("存档...",index,this.getLocalTime());
		
		cc.sys.localStorage.setItem("mt-saved-time-"+index,this.getLocalTime())
		
		cc.sys.localStorage.setItem("mt-saved-chapterConfig-"+index,JSON.stringify(config.chapterConfig));
		
		var chapterButtonState = [];
		for(var i=0;i<game.chapterButtonArr.length;i++){
			if(game.chapterButtonArr[i].getComponent(cc.Button).interactable)
				chapterButtonState[i]=1;
			else
				chapterButtonState[i]=0;
		}
		cc.sys.localStorage.setItem("mt-saved-chapterButtonConfig-"+index,JSON.stringify(chapterButtonState));
		
	
		cc.sys.localStorage.setItem("mt-saved-chapterNmb-"+index,game.chapterNmb);//当前楼层
		cc.sys.localStorage.setItem("mt-saved-keyNmb-"+index,game.keyNmb);//钥匙数量
		cc.sys.localStorage.setItem("mt-saved-keyNmbY-"+index,game.keyNmbY);//黄钥匙数量
		cc.sys.localStorage.setItem("mt-saved-keyNmbR-"+index,game.keyNmbR);//红钥匙数量
		cc.sys.localStorage.setItem("mt-saved-attack-"+index,game.attack);//攻击力
		cc.sys.localStorage.setItem("mt-saved-defends-"+index,game.defends);//防御力
		cc.sys.localStorage.setItem("mt-saved-hp-"+index,game.hp);//血量
		cc.sys.localStorage.setItem("mt-saved-iceAble-"+index,game.iceAble);//千年冰
		cc.sys.localStorage.setItem("mt-saved-tenAble-"+index,game.tenAble);//十字架
		cc.sys.localStorage.setItem("mt-saved-godAble-"+index,game.godAble);//降魔刀
		cc.sys.localStorage.setItem("mt-saved-goldNmb-"+index,game.goldNmb);//金币数
		cc.sys.localStorage.setItem("mt-saved-flyTNmb-"+index,game.flyTNmb);//对称飞机
		cc.sys.localStorage.setItem("mt-saved-flyAble-"+index,game.flyAble);//飞机
		cc.sys.localStorage.setItem("mt-saved-flyUNmb-"+index,game.flyUNmb);//向上飞机
		cc.sys.localStorage.setItem("mt-saved-flyDNmb-"+index,game.flyDNmb);//向下飞机
		cc.sys.localStorage.setItem("mt-saved-boomNmb-"+index,game.boomNmb);//炸弹数
		cc.sys.localStorage.setItem("mt-saved-price-"+index,game.price);//当前购买价格
		cc.sys.localStorage.setItem("mt-saved-playerPx-"+index,game.playerPx);//玩家所处地图中的x坐标
		cc.sys.localStorage.setItem("mt-saved-playerPy-"+index,game.playerPy);//玩家所处地图中的y坐标
		cc.sys.localStorage.setItem("mt-saved-upload1-"+index,game.upload1);//是否到达11
		cc.sys.localStorage.setItem("mt-saved-upload2-"+index,game.upload2);//是否到达21
		cc.sys.localStorage.setItem("mt-saved-upload3-"+index,game.upload3);//是否通关

		return true;
			
	},
	
	goonGame:function(config,game,index){
		
		
		console.log("读档...",index);
		
		if(cc.sys.localStorage.getItem("mt-saved-time-"+index)){
			
			config.chapterConfig = JSON.parse(cc.sys.localStorage.getItem("mt-saved-chapterConfig-"+index));
			
			game.chapterNmb=cc.sys.localStorage.getItem("mt-saved-chapterNmb-"+index)/1;//当前楼层
			game.keyNmb=cc.sys.localStorage.getItem("mt-saved-keyNmb-"+index)/1;//钥匙数量
			game.keyNmbY=cc.sys.localStorage.getItem("mt-saved-keyNmbY-"+index)/1;//黄钥匙数量
			game.keyNmbR=cc.sys.localStorage.getItem("mt-saved-keyNmbR-"+index)/1;//红钥匙数量
			game.attack=cc.sys.localStorage.getItem("mt-saved-attack-"+index)/1;//攻击力
			game.defends=cc.sys.localStorage.getItem("mt-saved-defends-"+index)/1;//防御力
			game.hp=cc.sys.localStorage.getItem("mt-saved-hp-"+index)/1;//血量
			game.iceAble=cc.sys.localStorage.getItem("mt-saved-iceAble-"+index)/1;//千年冰
			game.tenAble=cc.sys.localStorage.getItem("mt-saved-tenAble-"+index)/1;//十字架
			game.godAble=cc.sys.localStorage.getItem("mt-saved-godAble-"+index)/1;//降魔刀
			game.goldNmb=cc.sys.localStorage.getItem("mt-saved-goldNmb-"+index)/1;//金币数
			game.flyTNmb=cc.sys.localStorage.getItem("mt-saved-flyTNmb-"+index)/1;//对称飞机
			game.flyAble=cc.sys.localStorage.getItem("mt-saved-flyAble-"+index)/1;//飞机
			game.flyUNmb=cc.sys.localStorage.getItem("mt-saved-flyUNmb-"+index)/1;//向上飞机
			game.flyDNmb=cc.sys.localStorage.getItem("mt-saved-flyDNmb-"+index)/1;//向下飞机
			game.boomNmb=cc.sys.localStorage.getItem("mt-saved-boomNmb-"+index)/1;//炸弹数
			game.price=cc.sys.localStorage.getItem("mt-saved-price-"+index)/1;//当前购买价格
			game.playerPx=cc.sys.localStorage.getItem("mt-saved-playerPx-"+index)/1;//玩家所处地图中的x坐标
			game.playerPy=cc.sys.localStorage.getItem("mt-saved-playerPy-"+index)/1;//玩家所处地图中的y坐标
			game.upload1=cc.sys.localStorage.getItem("mt-saved-upload1-"+index);//是否到达11
			game.upload2=cc.sys.localStorage.getItem("mt-saved-upload2-"+index);//是否到达21
			game.upload3=cc.sys.localStorage.getItem("mt-saved-upload3-"+index);//是否通关
			
			
			var chapterButtonState = JSON.parse(cc.sys.localStorage.getItem("mt-saved-chapterButtonConfig-"+index));;
			for(var i=0;i<game.chapterButtonArr.length;i++){
				if(chapterButtonState[i]==1)
					game.chapterButtonArr[i].getComponent(cc.Button).interactable = true;
				else
					game.chapterButtonArr[i].getComponent(cc.Button).interactable = false;
			}
			
			
			game.dir = 0;
			game.resetAnimation();
			game.initAll();
			game.showLight();
			
			return true;
			
		}else{
			
			return false;
			
		}
	}
});
